import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core';
import { HttpService, SupDic, GridComponent } from 'lbf';
import { SFComponent, SFSchema } from '@delon/form';
import { STColumn } from '@delon/abc';
import { NzMessageService } from 'ng-zorro-antd';


@Component({
  selector: 'lb-gr',
  templateUrl: './lb_gr.html',
})
export class GrComponent implements OnInit {
  @Output() clickItem = new EventEmitter<string>();
  _dad017 = 0;
  isAddVisible = false;
  xzxxSchema: SFSchema = {
    properties: {
      AAC022: {
        type: 'string',
        title: '证件类型',
        enum: this.supDic.getSFDic('DAD074'),
        ui: {
          widget: 'select',
        },
        default: '0',
      },
      AAC002: { type: 'string', title: '社会保障号' },
      AAC003: { type: 'string', title: '姓名' },
      AAC006: { type: 'string', title: '出生日期', format: 'date' },
      AAC004: {
        type: 'string',
        title: '性别',
        enum: this.supDic.getSFDic('AAC004'),
        ui: {
          widget: 'select',
        },
      },
      AAC005: {
        type: 'string',
        title: '民族',
        enum: this.supDic.getSFDic('AAC005'),
        ui: {
          widget: 'select',
        },
      },
      AAC009: {
        type: 'string',
        title: '户籍性质',
        enum: this.supDic.getSFDic('AAC009'),
        ui: {
          widget: 'select',
        },
      },
      AAC010: { type: 'string', title: '户籍地址', ui: 'cascader' },
      EAE033: { type: 'string', title: '手机号码' },
    },
    ui: {
      spanLabelFixed: 100,
      grid: {
        span: 12,
      },
    },
    required: ['AAC022', 'AAC002', 'AAC003', 'AAC004', 'AAC006'],
  };

  jbxxSchema: SFSchema = {
    properties: {
      AAC002: { type: 'string', title: '社会保障号' },
      AAC003: { type: 'string', title: '姓名' },
      DAD032: { type: 'string', title: '对象', ui: { hidden: true } },
    },
  };

  columns: STColumn[] = [
    { title: '', index: 'RN', width: '20px' },
    /*{ title: '个人编号', index: 'AAC001', ui: { hidden: true } },*/
    { title: '姓名', index: 'AAC003', width: '50px' },
    { title: '社会保障号', index: 'AAC002', width: '100px' },
    { title: '性别', index: 'AAC004', width: '50px', dic: 'AAC004'},
    { title: '出生日期', index: 'AAC006', width: '50px' },
    { title: '户口性质', index: 'AAC009', width: '100px' , dic: 'AAC009'},
    { title: '手机号码', index: 'EAE033', width: '100px' },
    { title: '户籍地', index: 'AAC010', width: '50px' },
    { title: '居住地', index: 'AAE006', width: '80px' },
    {
      title: '操作区',
      width: '50px',
      buttons: [
        {
          text: '办理',
          click: (record: any) => this.tysjsl(record),
        },
      ],
    },
  ];

  params = { sname: 'JBXX_QUERY', queryparas: { DAD032: '2' } };

  
  @ViewChild('sf1', { static: false }) sf1: SFComponent;
  @ViewChild('st', { static: false }) st: GridComponent;
  
  @Input() set ZT(value:number) {
    this._zt = value
    this.reset();    
  }
  _zt

  reset(){
    this.sf1.reset();
    this.jbxxcx();
    // console.log('aaaaa');
  }

  tysjsl(record:any) {
    this.clickItem.emit(record);
  }

  handleCancel() {
    this.isAddVisible = false;
  }

  handleOkAdd() {
    
    this.lbservice.lbservice('FR_XXADD', {}).then(resdata => {
      if (resdata.code < 1) {
        this.msgSrv.error(resdata.errmsg);
      } else {
        this.msgSrv.info('新增成功');
      }
    });
  }

  // 基本信息查询
  jbxxcx() {
    this.sf1.setValue('/DAD032', '2');
    this.st.reload(this.sf1.value);
  }
  // 基本信息新增按钮
  xzjbxx() {    
    this.isAddVisible = true;
  }

 
  
  constructor(
    private lbservice: HttpService,
    private supDic: SupDic,
    public msgSrv: NzMessageService,
  ) {
    
  }

  ngOnInit() {
    
  }


}